package com.dns.customers.aoptest.model;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;

import java.beans.PropertyDescriptor;

/**
 * @author :  yulei
 * @data :  2018/6/11 15:56
 * @Version :  1.0
 **/

public class MyInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {

    //接口方法，在实例化bean之前调用
    public Object postProcessBeforeInstantiation(Class<?> beanClass, String beanName) throws BeansException {

        //仅对容器中的car Bean 处理
        if("car".equals(beanName)){
            System.out.println("InstantiationAware  BeanPostProcessor.postProcessBeforeInstantiation");
        }

        return null;
    }


    //接口方法，在实例化Bean 后调用
    @Override
    public boolean postProcessAfterInstantiation(Object bean, String beanName) throws BeansException {

        //仅对容器中的car Bean 处理
        if("car".equals(beanName)){
            System.out.println("InstantiationAware  BeanPostProcessor.postProcessAfterInstantiation");
        }


        return true;
    }


    //接口方法，在设置某个属性时调用
    @Override
    public PropertyValues postProcessPropertyValues(
            PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName)
            throws BeansException {

        //仅对容器中的car Bean 处理
        if("car".equals(beanName)){
            System.out.println("InstantiationAware  AwareBeanPostProcessor.postProcessPropertyValues");
        }
        return pvs;
    }



}
